package com.wzy.service.impl;

import com.wzy.dao.UserDao;
import com.wzy.dao.UserDaoFactory;
import com.wzy.dao.impl.UserDaoImpl;
import com.wzy.entity.User;
import com.wzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("userService")
public class UserServiceImpl implements UserService {

    //private UserDao userDao = new UserDaoImpl();

    //private UserDao userDao = UserDaoFactory.getInstance();

    @Resource
    private UserDao userDao;

    /**
     * 无参构造方法
     */
    public UserServiceImpl() {
    }

    /**
     * 用于dao属性赋值的构造方法
     * @param userDao
     */
    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public int save(User user) {
        System.out.println(user.getId());
        System.out.println(user.getUserName());
        System.out.println(user.getUserPassword());
        return userDao.save(user);
    }

    @Override
    public int delete(int id) {
        System.out.println("删除编号为"+id+"的用户");
        int r = 1/0;
        return userDao.delete(id);
    }
}
